package com.ruoyi.project.hissystem.conterllor;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hissystem.domain.SysExamCost;
import com.ruoyi.project.hissystem.domain.SysKeShi;
import com.ruoyi.project.hissystem.service.ISysKeShiService;
import com.ruoyi.project.system.domain.SysPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("system/keshi")
public class SysKeShiControllor extends BaseController {
    /*科室分页查询*/
    @Autowired
    private ISysKeShiService iSysKeShiService;
    @PreAuthorize("@ss.hasPermi('system:keshi:list')")
    @GetMapping("/index")
    @ResponseBody
    public TableDataInfo list(SysKeShi sysKeShi) {
        startPage();
        List<SysKeShi> sysKeShis = iSysKeShiService.selSysKeShiList(sysKeShi);
        return getDataTable(sysKeShis);
    }
    /*新增科室*/
    @PreAuthorize("@ss.hasPermi('system:keshi:add')")
    @Log(title = "费用项目管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    @ResponseBody
    public AjaxResult add(@RequestBody SysKeShi sysKeShi)
    {
        sysKeShi.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iSysKeShiService.insSysKeShi(sysKeShi));
    }


    /*根据id查询*/

    @PreAuthorize("@ss.hasPermi('system:keshi:query')")
    @GetMapping(value = "/{keshiid}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable int keshiid)
    {
        return AjaxResult.success(iSysKeShiService.selSysKeShiOne(keshiid));
    }


    /*修改科室*/
    @PreAuthorize("@ss.hasPermi('system:keshi:edit')")
    @Log(title = "科室项目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ResponseBody
    public AjaxResult edit(@RequestBody SysKeShi sysKeShi) {

        sysKeShi.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iSysKeShiService.upSysKeShi(sysKeShi));
    }

    /*删除科室项目信息*/

    @PreAuthorize("@ss.hasPermi('system:keshi:remove')")
    @Log(title = "科室项目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{keshiids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable int[] keshiids)
    {
        return toAjax(iSysKeShiService.datSysKeShi(keshiids));
    }

  /*导出*/

    @Log(title = "科室管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:keshi:export')")
    @GetMapping("/export")
    @ResponseBody
    public AjaxResult export(SysKeShi sysKeShi)
    {
        List<SysKeShi> sysKeShis = iSysKeShiService.selSysKeShiList(sysKeShi);
        ExcelUtil<SysKeShi> util = new ExcelUtil<SysKeShi>(SysKeShi.class);
        return util.exportExcel(sysKeShis, "科室数据");
    }
}
